// 结算界面
import Defines from './../MJ/defines'

cc.Class({
    extends: cc.Component,

    properties: {
        m_jieSuanIcon:[],                       // 结算玩家头像的父节点
        m_jieSuanShuYing:[],                    // 结算输赢的节点
        m_jieSuanPaoShou:[],                    // 结算炮手的节点
        m_jieSuanJieSuanInfo:[],                // 结算玩家信息的父节点
    },

    onLoad () {
        // 结算玩家头像的父节点
        var icon = this.node.getChildByName("Icon");
        // 结算炮手的节点
        var paoShou = this.node.getChildByName("PaoShou");
        // 结算输赢的节点
        var shuYing = this.node.getChildByName("ShuYing");
        // 结算玩家信息的父节点
        var info = this.node.getChildByName("Info");
        
        for (var num = 0; num < icon.children.length; num++) {
            this.m_jieSuanIcon.push(icon.children[num]);
            this.m_jieSuanPaoShou.push(paoShou.children[num]);
            this.m_jieSuanShuYing.push(shuYing.children[num]);
            this.m_jieSuanJieSuanInfo.push(info.children[num]);
        }
    },

    SetDataFun: function(playerID, data) {
        this.SetJiSuanIcon(1,"", "你");

        this.SetPaoShou(0);

        this.SetShuYing(2);
        
        var data = [1,2,3];
        this.SetJieSuanInfo(1,data);

        
        cc.log(Defines.playerData.SwitchViewChairID(0));
        cc.log(Defines.playerData.SwitchViewChairID(1));
        cc.log(Defines.playerData.SwitchViewChairID(2));
        cc.log(Defines.playerData.SwitchViewChairID(3));
    },

    // ***************************************************************************************结算界面处理
    // 头像名字设置
    // PlayerID                 玩家ID
    // iconData                 头像地址
    // name                     名字
    SetJiSuanIcon : function(playerID, iconData, name) {
        var sprite = this.m_jieSuanIcon[playerID].getChildByName("IconBox").getChildByName("New Node").getChildByName("iconImg").getComponent(cc.Sprite);
        var realUrl = cc.url.raw('resources/Communal/4.png');
        cc.loader.load(realUrl, function (err, texture) {
            var w = sprite.node.width;
            var h = sprite.node.height;
            var frame = new cc.SpriteFrame(texture);
            sprite.spriteFrame = frame;
        });

        this.m_jieSuanIcon[playerID].getChildByName("NameBox").getChildByName("Name").getComponent(cc.Label).string = name;
    },

    // 炮手的显示
    // PlayerID                     玩家ID
    SetPaoShou : function(playerID) {
        this.m_jieSuanPaoShou[playerID].active = true;
    },

    // 输赢的显示
    // PlayerID                     玩家ID
    SetShuYing : function(playerID) {
        this.m_jieSuanShuYing[playerID].active = true;
    },

    // 结算的信息
    // PlayerID                     玩家ID
    // data                         具体数据的数组
    SetJieSuanInfo : function(playerID, data) {
        for (var num = 0; num < this.m_jieSuanJieSuanInfo[playerID].children.length; num++) {
            this.m_jieSuanJieSuanInfo[playerID].children[num].getComponent(cc.Label).string = data[num];
        }
    },
});
